package com.example.myapplication.register;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

import com.example.day01.R;

public class RegisterActivity extends AppCompatActivity {
    EditText et_name,et_pwd,et_pwd_again;
    RadioButton rb_boy,rb_girl;
    CheckBox cb_1,cb_2,cb_3,cb_4;
    Button btn_login;
    private static final String TAG = "RegisterActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        initView();
    }

    private void initView() {
        et_name=findViewById(R.id.et_user_name);
        et_pwd=findViewById(R.id.et_user_pwd);
        et_pwd_again=findViewById(R.id.et_user_pwd_again);
        rb_boy=findViewById(R.id.rb_boy);
        rb_girl=findViewById(R.id.rb_girl);
        cb_1=findViewById(R.id.cb_1);
        cb_2=findViewById(R.id.cb_2);
        cb_3=findViewById(R.id.cb_3);
        cb_4=findViewById(R.id.cb_4);
        btn_login=findViewById(R.id.btn_login);
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name,pwd,pwd_again,sex,star;
                name=et_name.getText().toString().trim();
                pwd=et_pwd.getText().toString();
                sex="";
                star="";
                pwd_again=et_pwd_again.getText().toString();
                if (pwd.equals(pwd_again)) {
                    if (rb_boy.isChecked()) {
                        sex="男";
                    } else if (rb_girl.isChecked()) {
                        sex="女";
                    }
                    if (cb_1.isChecked()) {
                        star="刘德华";
                    }
                    if (cb_2.isChecked()) {
                        if (star.equals("")) {
                            star="周星驰";
                        }else {
                            star=star+"\n周星驰";
                        }

                    }
                    if (cb_3.isChecked()) {
                        if (star.equals("")){
                            star="刘亦菲";
                        }else {
                            star=star+"\n刘亦菲";
                        }
                    }
                    if (cb_4.isChecked()) {
                        if (star.equals("")) {
                            star="其他";
                        }else {
                            star=star+"\n其他";
                        }
                    }
                    Log.d(TAG, "用户名："+name+"\n密码:"+pwd+"\n性别:"+sex+"\n喜欢的明星:"+star);



                }else {
                    Toast.makeText(RegisterActivity.this, "注册失败，请确认密码！", Toast.LENGTH_SHORT).show();
                }

            }
        });
    }

}
